/*
 * JPanelClassify.java
 *
 * Created on 31/08/2010, 16:22:27
 */
package view.jpanel;

import annotations.ModuleAnnotation;
import controller.FacadeHost;
import controller.Host;
import controller.ModuleFactory;
import interfaces.Base;
import interfaces.PersistenceModuleInterface;
import interfaces.mining.classify.BaseClassify;
import interfaces.mining.classify.ClassifierModuleInterface;
import interfaces.mining.classify.ConfusionMatrix;
import interfaces.mining.classify.EvaluationMetricModuleInterface;
import interfaces.mining.classify.PartitionModuleInterface;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.lang.reflect.InvocationTargetException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import model.ModuleAvailable;
import moduledefault.pca.Pca;
import view.jdialog.JDialogClassify;
import view.jdialog.JDialogConfig;

/**
 *
 * @author evaristowb
 */
public class JPanelComparacaoRD extends javax.swing.JPanel implements Observer, PersistenceModuleInterface {

    private ArrayList<JRadioButton> arrayListRadioButtonPartionModules = new ArrayList<JRadioButton>();
    private ArrayList<JCheckBox> arrayListCheckBoxEvalutionModules = new ArrayList<JCheckBox>();
    private ArrayList<PartitionModuleInterface> arrayListPartitionModuleConfigureds = new ArrayList<PartitionModuleInterface>();
    private ArrayList<EvaluationMetricModuleInterface> arrayListEvaluationMetricModuleConfigureds = new ArrayList<EvaluationMetricModuleInterface>();
    private ClassifierModuleInterface classifierModule = null;
    private ClassifierModuleInterface classifierModuleTrained = null;
    private ArrayList<Base> arrayListBases = new ArrayList<Base>();

    /**
     * Creates new form JPanelClassify
     */
    public JPanelComparacaoRD() {
        initComponents();
        FacadeHost.getHost().addObserver(this);
        jComboBoxAvailableTechinics.addItem("");
        for (ModuleAvailable<ClassifierModuleInterface> c : ModuleFactory.getArrayListClassifierModules()) {
            jComboBoxAvailableTechinics.addItem(c);
        }

        //Load Partition Modules
        int c = 0;
        for (int i = 0; i < ModuleFactory.getArrayListPartionModules().size(); i++) {
            ModuleAvailable<PartitionModuleInterface> p = ModuleFactory.getArrayListPartionModules().get(i);
            try {
                final JRadioButton jRadioButton = new javax.swing.JRadioButton();
                jRadioButton.setText(p.getName());
                final PartitionModuleInterface partitionModule = p.getConstructor().newInstance();
                partitionModule.setHost(FacadeHost.getHost());

                GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = c;
                gridBagConstraints.ipadx = 7;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
                gridBagConstraints.weightx = 55.0;
                if (i == ModuleFactory.getArrayListPartionModules().size() - 1) {
                    gridBagConstraints.weighty = 0.01;
                }
                jPanelPartitionIntern.add(jRadioButton, gridBagConstraints);

                try {
                    if (partitionModule.getPainelConfig() != null) {
                        final JButton jButton = new javax.swing.JButton();
                        jButton.setFont(new java.awt.Font("Calibri", 0, 12));
                        jButton.setText("Config");

                        jButton.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {
                                jRadioButton.setSelected(true);
                                JDialogConfig jDialogConfig = new JDialogConfig(FacadeHost.getViewMain(), true);
                                jDialogConfig.addPanel(partitionModule.getPainelConfig());
                                partitionModule.setJDialogConfig(jDialogConfig);
                                jDialogConfig.setVisible(true);

//                                JDialog jDialog = new JDialog(FacadeHost.getViewMain(), true);
//                                jDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
//                                GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
//                                gridBagConstraints.gridx = 0;
//                                gridBagConstraints.gridy = 0;
//                                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
////                                jDialog.getContentPane().add(partitionModule.getPainelConfig(), gridBagConstraints);
//                                jDialog.getContentPane().add(partitionModule.getPainelConfig());
//                                jDialog.setSize(partitionModule.getPainelConfig().getPreferredSize());
//                                partitionModule.setJDialogConfig(jDialog);
//                                jDialog.setVisible(true);

                            }
                        });

                        gridBagConstraints = new java.awt.GridBagConstraints();
                        gridBagConstraints.gridx = 1;
                        gridBagConstraints.gridy = c;
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
                        gridBagConstraints.weightx = 45.0;
                        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 8);
                        jPanelPartitionIntern.add(jButton, gridBagConstraints);
                    }
                } catch (UnsupportedOperationException e) {
                }

                arrayListPartitionModuleConfigureds.add(partitionModule);
                buttonGroup.add(jRadioButton);
                arrayListRadioButtonPartionModules.add(jRadioButton);
                c++;

            } catch (InstantiationException ex) {
                Logger.getLogger(JPanelComparacaoRD.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(JPanelComparacaoRD.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalArgumentException ex) {
                Logger.getLogger(JPanelComparacaoRD.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InvocationTargetException ex) {
                Logger.getLogger(JPanelComparacaoRD.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        if (!arrayListRadioButtonPartionModules.isEmpty()) {
            arrayListRadioButtonPartionModules.get(0).setSelected(true);
        }

        //Load Evaluation Metrics Modules
        c = 0;
        for (int i = 0; i < ModuleFactory.getArrayListEvaluationMetrics().size(); i++) {
            ModuleAvailable<EvaluationMetricModuleInterface> p = ModuleFactory.getArrayListEvaluationMetrics().get(i);
            try {
                JCheckBox jCheckBox = new javax.swing.JCheckBox();
                jCheckBox.setText(p.getName());
                final EvaluationMetricModuleInterface evaluationModule = p.getConstructor().newInstance();
                evaluationModule.setHost(FacadeHost.getHost());

                GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = c;
                gridBagConstraints.ipadx = 7;
                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
                gridBagConstraints.weightx = 55.0;
                if (i == ModuleFactory.getArrayListEvaluationMetrics().size() - 1) {
                    gridBagConstraints.weighty = 0.01;
                }
                jPanelMeasuresIntern.add(jCheckBox, gridBagConstraints);

                try {
                    if (evaluationModule.getPainelConfig() != null) {
                        final JButton jButton = new javax.swing.JButton();
                        jButton.setFont(new java.awt.Font("Calibri", 0, 12));
                        jButton.setText("Config");

                        jButton.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {
                                JDialogConfig jDialogConfig = new JDialogConfig(FacadeHost.getViewMain(), true);
                                jDialogConfig.addPanel(evaluationModule.getPainelConfig());
                                evaluationModule.setJDialogConfig(jDialogConfig);
                                jDialogConfig.setVisible(true);
                            }
                        });

                        gridBagConstraints = new java.awt.GridBagConstraints();
                        gridBagConstraints.gridx = 1;
                        gridBagConstraints.gridy = c;
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
                        gridBagConstraints.weightx = 45.0;
                        gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 8);
                        jPanelPartitionIntern.add(jButton, gridBagConstraints);
                    }
                } catch (UnsupportedOperationException e) {
                }


                arrayListEvaluationMetricModuleConfigureds.add(evaluationModule);
                arrayListCheckBoxEvalutionModules.add(jCheckBox);
                c++;

            } catch (InstantiationException ex) {
                Logger.getLogger(JPanelComparacaoRD.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(JPanelComparacaoRD.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalArgumentException ex) {
                Logger.getLogger(JPanelComparacaoRD.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InvocationTargetException ex) {
                Logger.getLogger(JPanelComparacaoRD.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        for (JCheckBox jCheckBoxEvaluationModule : arrayListCheckBoxEvalutionModules) {
            jCheckBoxEvaluationModule.setSelected(true);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        buttonGroup = new javax.swing.ButtonGroup();
        jPanel = new javax.swing.JPanel();
        jLabelAvailableTechinics = new javax.swing.JLabel();
        jComboBoxAvailableTechinics = new javax.swing.JComboBox();
        jButtonConfiguration = new javax.swing.JButton();
        jPanelPartition = new javax.swing.JPanel();
        jScrollPanePartition = new javax.swing.JScrollPane();
        jPanelPartitionIntern = new javax.swing.JPanel();
        jPanelMeasures = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanelMeasuresIntern = new javax.swing.JPanel();
        jScrollPaneRunning = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButtonVisualize = new javax.swing.JButton();
        jButtonTrainSelecaoFB = new javax.swing.JButton();
        jButtonClassify = new javax.swing.JButton();
        jScrollPaneResult = new javax.swing.JScrollPane();
        jListResult = new javax.swing.JList();
        jButtonTrainPCA = new javax.swing.JButton();
        jButtonTrainSelecaoSBS = new javax.swing.JButton();
        jButtonTrainSelecaoSFS = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Técnica de Classificação", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 18))); // NOI18N
        jPanel.setLayout(new java.awt.GridBagLayout());

        jLabelAvailableTechinics.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        jLabelAvailableTechinics.setText("Técnica a ser utilizada:"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 27, 0, 0);
        jPanel.add(jLabelAvailableTechinics, gridBagConstraints);

        jComboBoxAvailableTechinics.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxAvailableTechinicsActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.ipadx = 300;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(1, 36, 0, 0);
        jPanel.add(jComboBoxAvailableTechinics, gridBagConstraints);

        jButtonConfiguration.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        jButtonConfiguration.setText("Configurações");
        jButtonConfiguration.setEnabled(false);
        jButtonConfiguration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConfigurationActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 30.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
        jPanel.add(jButtonConfiguration, gridBagConstraints);

        jPanelPartition.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Particionamento", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 12))); // NOI18N

        jScrollPanePartition.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jScrollPanePartition.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPanePartition.setViewportBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jPanelPartitionIntern.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jPanelPartitionIntern.setLayout(new java.awt.GridBagLayout());
        jScrollPanePartition.setViewportView(jPanelPartitionIntern);

        javax.swing.GroupLayout jPanelPartitionLayout = new javax.swing.GroupLayout(jPanelPartition);
        jPanelPartition.setLayout(jPanelPartitionLayout);
        jPanelPartitionLayout.setHorizontalGroup(
            jPanelPartitionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPanePartition, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
        );
        jPanelPartitionLayout.setVerticalGroup(
            jPanelPartitionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPanePartition, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE)
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.ipadx = 180;
        gridBagConstraints.ipady = 80;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 35.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel.add(jPanelPartition, gridBagConstraints);

        jPanelMeasures.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Avaliação", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 12))); // NOI18N

        jScrollPane3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane3.setViewportBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jPanelMeasuresIntern.setLayout(new java.awt.GridBagLayout());
        jScrollPane3.setViewportView(jPanelMeasuresIntern);

        javax.swing.GroupLayout jPanelMeasuresLayout = new javax.swing.GroupLayout(jPanelMeasures);
        jPanelMeasures.setLayout(jPanelMeasuresLayout);
        jPanelMeasuresLayout.setHorizontalGroup(
            jPanelMeasuresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 204, Short.MAX_VALUE)
            .addGroup(jPanelMeasuresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))
        );
        jPanelMeasuresLayout.setVerticalGroup(
            jPanelMeasuresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 121, Short.MAX_VALUE)
            .addGroup(jPanelMeasuresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 121, Short.MAX_VALUE))
        );

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.ipadx = 180;
        gridBagConstraints.ipady = 80;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weighty = 35.0;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        jPanel.add(jPanelMeasures, gridBagConstraints);

        jScrollPaneRunning.setBackground(new java.awt.Color(255, 255, 255));
        jScrollPaneRunning.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPaneRunning.setViewportView(jTextArea1);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 363;
        gridBagConstraints.ipady = 320;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(14, 6, 0, 6);
        jPanel.add(jScrollPaneRunning, gridBagConstraints);

        jButtonVisualize.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        jButtonVisualize.setText("Visualizar Modelo");
        jButtonVisualize.setEnabled(false);
        jButtonVisualize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVisualizeActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 6);
        jPanel.add(jButtonVisualize, gridBagConstraints);

        jButtonTrainSelecaoFB.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        jButtonTrainSelecaoFB.setText("Selecao FB");
        jButtonTrainSelecaoFB.setEnabled(false);
        jButtonTrainSelecaoFB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTrainSelecaoFBActionPerformed(evt);
            }
        });
        jPanel.add(jButtonTrainSelecaoFB, new java.awt.GridBagConstraints());

        jButtonClassify.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        jButtonClassify.setText("Classificar");
        jButtonClassify.setEnabled(false);
        jButtonClassify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonClassifyActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
        jPanel.add(jButtonClassify, gridBagConstraints);

        jScrollPaneResult.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Lista de Resultados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1, 12))); // NOI18N

        jListResult.setModel(new DefaultListModel());
        jListResult.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jListResult.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jListResultMouseClicked(evt);
            }
        });
        jListResult.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jListResultKeyReleased(evt);
            }
        });
        jScrollPaneResult.setViewportView(jListResult);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 30.0;
        jPanel.add(jScrollPaneResult, gridBagConstraints);

        jButtonTrainPCA.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        jButtonTrainPCA.setText("Treinar PCA");
        jButtonTrainPCA.setEnabled(false);
        jButtonTrainPCA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTrainPCAActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 0);
        jPanel.add(jButtonTrainPCA, gridBagConstraints);

        jButtonTrainSelecaoSBS.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        jButtonTrainSelecaoSBS.setText("Selecao SBS");
        jButtonTrainSelecaoSBS.setEnabled(false);
        jButtonTrainSelecaoSBS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTrainSelecaoSBSActionPerformed(evt);
            }
        });
        jPanel.add(jButtonTrainSelecaoSBS, new java.awt.GridBagConstraints());

        jButtonTrainSelecaoSFS.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        jButtonTrainSelecaoSFS.setText("Selecao SFS");
        jButtonTrainSelecaoSFS.setEnabled(false);
        jButtonTrainSelecaoSFS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTrainSelecaoSFSActionPerformed(evt);
            }
        });
        jPanel.add(jButtonTrainSelecaoSFS, new java.awt.GridBagConstraints());

        jButton1.setText("todos");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel.add(jButton1, new java.awt.GridBagConstraints());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 702, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 702, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 501, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonVisualizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVisualizeActionPerformed
        jButtonVisualizeActionPerformed();
    }//GEN-LAST:event_jButtonVisualizeActionPerformed

    private void jListResultMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListResultMouseClicked
//        if (evt.getClickCount() == 2)

        jListResultActionPerformed();
    }//GEN-LAST:event_jListResultMouseClicked

    private void jComboBoxAvailableTechinicsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxAvailableTechinicsActionPerformed
        jComboBoxAvailableTechinicsActionPerformed();
    }//GEN-LAST:event_jComboBoxAvailableTechinicsActionPerformed

    private void jButtonConfigurationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConfigurationActionPerformed
        jButtonConfigurationActionPerformed();
    }//GEN-LAST:event_jButtonConfigurationActionPerformed

    private void jButtonTrainSelecaoFBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTrainSelecaoFBActionPerformed

        new Thread(new Runnable() {
            public void run() {

                jButtonTrainSelecaoFBActionPerformed();

            }
        }).start();

    }//GEN-LAST:event_jButtonTrainSelecaoFBActionPerformed

    private void jListResultKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jListResultKeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_UP
                || evt.getKeyCode() == KeyEvent.VK_DOWN
                || evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN
                || evt.getKeyCode() == KeyEvent.VK_PAGE_UP
                || evt.getKeyCode() == KeyEvent.VK_END
                || evt.getKeyCode() == KeyEvent.VK_HOME) {
            jListResultActionPerformed();
        }
    }//GEN-LAST:event_jListResultKeyReleased

    private void jButtonClassifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonClassifyActionPerformed
        jButtonClassifyActionPerformed();
    }//GEN-LAST:event_jButtonClassifyActionPerformed

    private void jButtonTrainPCAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTrainPCAActionPerformed
        // TODO add your handling code here:
        new Thread(new Runnable() {
            public void run() {
                jButtonTrainPCAActionPerformed();
            }
        }).start();

    }//GEN-LAST:event_jButtonTrainPCAActionPerformed

    private void jButtonTrainSelecaoSBSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTrainSelecaoSBSActionPerformed
        // TODO add your handling code here:
        new Thread(new Runnable() {
            public void run() {
                jButtonTrainSelecaoSBSActionPerformed();
            }
        }).start();

    }//GEN-LAST:event_jButtonTrainSelecaoSBSActionPerformed

    private void jButtonTrainSelecaoSFSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTrainSelecaoSFSActionPerformed
        // TODO add your handling code here:
        new Thread(new Runnable() {
            public void run() {
                jButtonTrainSelecaoSFSActionPerformed();
            }
        }).start();

    }//GEN-LAST:event_jButtonTrainSelecaoSFSActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        System.out.println("Método\tQntCaracteristica\taccuracy\ttempo");

        jButtonTrainSelecaoFBActionPerformed();
        System.out.println("");
        jButtonTrainSelecaoSBSActionPerformed();
        System.out.println("");
        jButtonTrainSelecaoSFSActionPerformed();
        System.out.println("");
        jButtonTrainPCAActionPerformed();



    }//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonClassify;
    private javax.swing.JButton jButtonConfiguration;
    private javax.swing.JButton jButtonTrainPCA;
    private javax.swing.JButton jButtonTrainSelecaoFB;
    private javax.swing.JButton jButtonTrainSelecaoSBS;
    private javax.swing.JButton jButtonTrainSelecaoSFS;
    private javax.swing.JButton jButtonVisualize;
    private javax.swing.JComboBox jComboBoxAvailableTechinics;
    private javax.swing.JLabel jLabelAvailableTechinics;
    private javax.swing.JList jListResult;
    private javax.swing.JPanel jPanel;
    private javax.swing.JPanel jPanelMeasures;
    private javax.swing.JPanel jPanelMeasuresIntern;
    private javax.swing.JPanel jPanelPartition;
    private javax.swing.JPanel jPanelPartitionIntern;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPanePartition;
    private javax.swing.JScrollPane jScrollPaneResult;
    private javax.swing.JScrollPane jScrollPaneRunning;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables

    public void update(Observable o, Object o1) {
        if (o instanceof Host) {
            Host h = (Host) o;
            if ((o1 instanceof Base) && ((Base) o1).hasMeta()) {
                arrayListBases.add((Base) o1);
            }

            if (o1 instanceof ClassifierModuleInterface) {
                ClassifierModuleInterface classifierModule = (ClassifierModuleInterface) o1;
                classifierModule.setHost(h);

                ClassifyText classifyJTextArea = new ClassifyText();
                classifyJTextArea.setModuleAvailable(classifierModule);
                classifyJTextArea.setJTextArea(classifierModule.getJTextArea());
                ((DefaultListModel) jListResult.getModel()).addElement(classifyJTextArea);
            }
        }
    }

    private void jComboBoxAvailableTechinicsActionPerformed() {
        if (jComboBoxAvailableTechinics.getSelectedItem() instanceof ModuleAvailable) {
            try {
                classifierModule = ((ModuleAvailable<ClassifierModuleInterface>) jComboBoxAvailableTechinics.getSelectedItem()).getConstructor().newInstance();
                classifierModule.setHost(FacadeHost.getHost());
                //classifierModule.setTextArea(jTextAreaRunning);
                if (classifierModule.getPainelConfig() != null) {
                    jButtonConfiguration.setEnabled(true);
                } else {
                    jButtonConfiguration.setEnabled(false);
                }
                jButtonTrainSelecaoFB.setEnabled(true);
                jButtonTrainSelecaoSBS.setEnabled(true);
                jButtonTrainSelecaoSFS.setEnabled(true);
                jButtonTrainPCA.setEnabled(true);
//                jButtonVisualize.setEnabled(false);
//                jButtonClassify.setEnabled(false);
            } catch (InstantiationException ex) {
                Logger.getLogger(JPanelPreprocess.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                Logger.getLogger(JPanelPreprocess.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IllegalArgumentException ex) {
                Logger.getLogger(JPanelPreprocess.class.getName()).log(Level.SEVERE, null, ex);
            } catch (InvocationTargetException ex) {
                Logger.getLogger(JPanelPreprocess.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            jButtonConfiguration.setEnabled(false);
            jButtonTrainSelecaoFB.setEnabled(false);
//            jButtonClassify.setEnabled(false);
//            jButtonVisualize.setEnabled(false);
            classifierModule = null;
        }
    }

    private void jButtonConfigurationActionPerformed() {
        JDialogConfig jDialogConfig = new JDialogConfig(FacadeHost.getViewMain(), true);
        jDialogConfig.addPanel(classifierModule.getPainelConfig());
        classifierModule.setJDialogConfig(jDialogConfig);
        jDialogConfig.setVisible(true);
    }

    private void jButtonVisualizeActionPerformed() {
        JDialogConfig jDialogConfig = new JDialogConfig(FacadeHost.getViewMain(), true);
        jDialogConfig.addPanel(classifierModuleTrained.getCreatedModel());

        //classifierModule.setJDialogConfig(jDialogConfig);
        jDialogConfig.setVisible(true);
    }

    private synchronized void jListResultActionPerformed() {
        //StringBuffer stringBuffer = new StringBuffer();
        ClassifyText classifyJTextArea = (ClassifyText) jListResult.getSelectedValue();
        classifierModuleTrained = classifyJTextArea.getModuleAvailable();
        jScrollPaneRunning.setViewportView(classifyJTextArea.getJTextArea());

        // jButtonTrain.setEnabled(true);
        jButtonClassify.setEnabled(true);


//        try {
//            if (classifierModuleTrained.getPainelConfig() != null) {
//                jButtonConfiguration.setEnabled(true);
//            } else {
//                jButtonConfiguration.setEnabled(false);
//            }
//        } catch (UnsupportedOperationException ex) {
//            jButtonConfiguration.setEnabled(false);
//        }
/*    COMENTADO PARA FUNCIONAMENTO MAIS RAPIDO
         try {
         if (classifierModuleTrained.getCreatedModel() != null) {
         jButtonVisualize.setEnabled(true);
         } else {
         jButtonVisualize.setEnabled(false);
         }
         } catch (UnsupportedOperationException ex) {
         jButtonVisualize.setEnabled(false);
         }
         */
        revalidate();
    }

    private void jButtonClassifyActionPerformed() {
        Base base = arrayListBases.get(arrayListBases.size() - 1);
        JDialogClassify jd = new JDialogClassify(FacadeHost.getViewMain(), true, base, classifierModuleTrained);
        jd.setVisible(true);
    }

    public Object getSave() {
        return classifierModuleTrained;
    }

    public void setOpen(Object o) {
        this.classifierModuleTrained = (ClassifierModuleInterface) o;
    }

    private ArrayList<Base> gerarConjuntos(Base b, int num) {
        ArrayList<Base> conjuntoBases = new ArrayList<Base>();

        ArrayList<int[]> combinacoes = gerarCombinacoes(b.getAtributes().length - 1, num);

        for (int i = 0; i < combinacoes.size(); i++) {
            conjuntoBases.add(gerarBase(combinacoes.get(i), b));
        }

        return conjuntoBases;

    }

    private ArrayList<int[]> gerarCombinacoes(int numeroTotal, int tamanhoConjunto) {
        ArrayList<int[]> ret = new ArrayList<int[]>();

        int[] comb = new int[tamanhoConjunto];
        numeroTotal--;
        for (int i = 0; i < comb.length; i++) {
            comb[i] = numeroTotal--;
        }
        ret.add(comb);
        while (true) {
            comb = reduz(comb.clone());
            if (comb != null) {
                ret.add(comb);
            } else {
                break;
            }

        }


        return ret;
    }

    private Base gerarBase(int[] indexColunas, Base b) {
        Base novaBase = new Base();
        novaBase.setOutput(b.getOutput().clone());

        String[] novosAtributos = new String[indexColunas.length + 1];
        for (int i = 0; i < indexColunas.length; i++) {
            novosAtributos[i] = b.getAtributes()[indexColunas[i]];
        }
        novosAtributos[novosAtributos.length - 1] = b.getAtributes()[b.getAtributes().length - 1];
        novaBase.setAtributes(novosAtributos);

        Object[][] dados = b.getInput();
        Object[][] novosDados = new Object[dados.length][indexColunas.length];
        for (int col = 0; col < indexColunas.length; col++) {
            for (int obs = 0; obs < dados.length; obs++) {
                novosDados[obs][col] = dados[obs][indexColunas[col]];

            }
        }
        novaBase.setInput(novosDados);


        return novaBase;
    }

    private int[] reduz(int[] teste) {

        for (int j = teste.length - 1; j >= 0; j--) {
            int v = teste[j];
            for (int i = j; i < teste.length; i++) {
                teste[i] = --v;
            }
            if (teste[teste.length - 1] >= 0) {
                break;
            }
        }
        if (teste[teste.length - 1] >= 0) {
            return teste;
        } else {
            return null;
        }


    }

//    private int[] reduz(int[] comb) {
//        if (comb[comb.length - 1] > 0) {
//            int[] ret = comb.clone();
//            ret[ret.length - 1]--;
//            return ret;
//        } else {
//            int ini = comb[0];
//            int ret[] = comb.clone();
//            ini--;
//            for (int i = 0; i < ret.length; i++) {
//                ret[i] = ini--;
//            }
//            if (ini < -1) {
//                return null;
//            } else {
//                return ret;
//            }
//        }
//    }
    private void jButtonTrainSelecaoSBSActionPerformed() {
        Base b = arrayListBases.get(arrayListBases.size() - 1).clone();
        classifierModule.setTextArea(jTextArea1);

        long t = System.currentTimeMillis();
        for (int lol = b.getAtributes().length - 1; lol > 0; lol--) {
            jTextArea1.append("==================================\n");
            jTextArea1.append("Seleção com " + lol + " Caracteristicas\n");

            ArrayList<Base> bases = gerarConjuntos(b, lol);


            double melhorResultado = Double.MIN_VALUE;
            int indexMelhorResultado = 0;

            for (int i = 0; i < bases.size(); i++) {
                double[] evaluationGlobal = rodar(bases.get(i));
                if (evaluationGlobal[0] > melhorResultado) {
                    melhorResultado = evaluationGlobal[0];
                    indexMelhorResultado = i;
                }
            }

            jTextArea1.append(util.Util.getHoraMinSegMiliSeg(System.currentTimeMillis() - t) + "\n");
            System.out.println("SeleçãoSBS\t" + lol + "\t" + melhorResultado + "\t" + util.Util.getHoraMinSegMiliSeg(System.currentTimeMillis() - t));

            b = bases.get(indexMelhorResultado);



        }
    }

    private void jButtonTrainSelecaoSFSActionPerformed() {
        Base b = arrayListBases.get(arrayListBases.size() - 1).clone();
        classifierModule.setTextArea(jTextArea1);
        Base atual = null;

        long t = System.currentTimeMillis();
        for (int lol = 1; lol < b.getAtributes().length; lol++) {
            jTextArea1.append("==================================\n");
            jTextArea1.append("Seleção com " + lol + " Caracteristicas\n");

            ArrayList<Base> bases = gerarConjuntosForward(atual, b);

            double melhorResultado = Double.MIN_VALUE;
            int indexMelhorResultado = 0;

            for (int i = 0; i < bases.size(); i++) {
                double[] evaluationGlobal = rodar(bases.get(i));
                if (evaluationGlobal[0] > melhorResultado) {
                    melhorResultado = evaluationGlobal[0];
                    indexMelhorResultado = i;
                }
            }


            jTextArea1.append(util.Util.getHoraMinSegMiliSeg(System.currentTimeMillis() - t) + "\n");
            atual = bases.get(indexMelhorResultado);

            System.out.println("SeleçãoSFS\t" + lol + "\t" + melhorResultado + "\t" + util.Util.getHoraMinSegMiliSeg(System.currentTimeMillis() - t));



        }
    }

    private ArrayList<Base> gerarConjuntosForward(Base atual, Base b) {
        ArrayList<Base> bases = new ArrayList<Base>();

        if (atual != null) {
            int[] colunasContem = new int[atual.getAtributes().length];
            int cont = 0;
            ArrayList<Integer> colunasNaoContem = new ArrayList<Integer>();

            for (int j = 0; j < b.getAtributes().length - 1; j++) {
                boolean contem = false;
                for (int i = 0; i < atual.getAtributes().length - 1; i++) {

                    if (atual.getAtributes()[i].compareTo(b.getAtributes()[j]) == 0) {
                        colunasContem[cont++] = j;
                        contem = true;
                        break;
                    }
                }
                if (!contem) {
                    colunasNaoContem.add(j);
                }
            }

            for (int i = 0; i < colunasNaoContem.size(); i++) {
                colunasContem[colunasContem.length - 1] = colunasNaoContem.get(i);
                bases.add(gerarBase(colunasContem, b));
            }
        } else {
            for (int i = 0; i < b.getAtributes().length - 1; i++) {
                int[] coluna = new int[1];
                coluna[0] = i;
                bases.add(gerarBase(coluna, b));
            }
        }

        return bases;
    }

//    private void jTextAreaRunningComponentResized() {
//        jTextAreaRunning.setCaretPosition(jTextAreaRunning.getText().length());
//    }
    class ClassifyText {

        final DateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        private JTextArea text;
        private ClassifierModuleInterface moduleAvailable;
        private Date date;

        public ClassifyText() {
            date = new Date();
        }

        /**
         * returns the text area
         *
         * @return
         */
        public JTextArea getJTextArea() {
            return text;
        }

        /**
         * sets the text area
         *
         * @param text
         */
        public void setJTextArea(JTextArea text) {
            this.text = text;
        }

        /**
         * returns the module available
         *
         * @return
         */
        public ClassifierModuleInterface getModuleAvailable() {
            return moduleAvailable;
        }

        /**
         * sets the module available
         *
         * @param moduleAvailable
         */
        public void setModuleAvailable(ClassifierModuleInterface moduleAvailable) {
            this.moduleAvailable = moduleAvailable;
        }

        @Override
        public String toString() {
            return formatter.format(date)
                    + " " + moduleAvailable.getClass().getAnnotation(ModuleAnnotation.class).name();
        }
    }

    /**
     * action performed by the jbuttontrain button
     */
    private void jButtonTrainSelecaoFBActionPerformed() {
        Base b = arrayListBases.get(arrayListBases.size() - 1).clone();
        classifierModule.setTextArea(jTextArea1);

        long t = System.currentTimeMillis();
        for (int lol = 1; lol < b.getAtributes().length; lol++) {
            jTextArea1.append("==================================\n");
            jTextArea1.append("Seleção com " + lol + " Caracteristicas\n");

            System.gc();
            ArrayList<Base> bases = gerarConjuntos(b, lol);


            double melhorResultado = Double.MIN_VALUE;
            int indexMelhorResultado = 0;

            for (int i = 0; i < bases.size(); i++) {
                double[] evaluationGlobal = rodar(bases.get(i));                
                if (evaluationGlobal[0] > melhorResultado) {
                    melhorResultado = evaluationGlobal[0];
                    indexMelhorResultado = i;
                }
            }           
            

            jTextArea1.append(util.Util.getHoraMinSegMiliSeg(System.currentTimeMillis() - t) + "\n");

            System.out.println("SeleçãoFB\t" + lol + "\t" + melhorResultado + "\t" + util.Util.getHoraMinSegMiliSeg(System.currentTimeMillis() - t));



        }
    }

//    private void jButtonTrainPCAActionPerformed() {
//
//        Base b = arrayListBases.get(arrayListBases.size() - 1);
//        moduledefault.pca.Pca pca;
//        classifierModule.setTextArea(jTextArea1);
//
//        for (int lol = b.getAtributes().length - 1; lol > 0; lol--) {
//            pca = new Pca(b);
//            jTextArea1.append("==================================\n");
//            jTextArea1.append("PCA com " + lol + " Caracteristicas\n");
//            long t = System.currentTimeMillis();
//            pca.calcula();
//            pca.extrair(lol);
//            t = System.currentTimeMillis() - t;
//            jTextArea1.append(util.Util.getHoraMinSegMiliSeg(t) + "\n");
//
//            BaseClassify[] baseClassifiers = null;
//            Base base = arrayListBases.get(arrayListBases.size() - 1);
//            for (int i = 0; i < arrayListRadioButtonPartionModules.size(); i++) {
//                if (arrayListRadioButtonPartionModules.get(i).isSelected()) {
//                    baseClassifiers = arrayListPartitionModuleConfigureds.get(i).partition(base);
//                    break;
//                }
//            }
//            ArrayList<ConfusionMatrix> arrayListConfusionMatrixs = new ArrayList<ConfusionMatrix>();
//
//            long tempo = System.currentTimeMillis();
//
//            jTextArea1.append("==================");
//
//            classifierModule.createInstanceClissify(base.getAtributes(), base.getClasses());
//            jTextArea1.append(" ==============\n");
//            for (BaseClassify baseClassify : baseClassifiers) {
//
//
//                classifierModule.train(baseClassify.getTrain().getInput(), baseClassify.getTrain().getOutput());
//                ConfusionMatrix confusionMatrix = new ConfusionMatrix();
//                confusionMatrix.setClasses(base.getClasses());
//                for (int i = 0; i < baseClassify.getTest().getInput().length; i++) {
//                    confusionMatrix.addValue(baseClassify.getTest().getOutput()[i],
//                            classifierModule.test(baseClassify.getTest().getInput()[i]));
//                }
////                jTextArea1.append("\n============== Matriz de Confusão ==============\n");
////                jTextArea1.append(confusionMatrix.toString() + "\n\n");
//                arrayListConfusionMatrixs.add(confusionMatrix);
//            }
//
//            tempo = System.currentTimeMillis() - tempo;
//            jTextArea1.append(util.Util.getHoraMinSegMiliSeg(tempo) + "\n");
//
//            jTextArea1.append("============== Métricas de Avaliação ==============\n");
//            for (int i = 0; i < arrayListCheckBoxEvalutionModules.size(); i++) {
//                if (arrayListCheckBoxEvalutionModules.get(i).isSelected()) {
//                    arrayListEvaluationMetricModuleConfigureds.get(i).setTextArea(jTextArea1);
//                    arrayListEvaluationMetricModuleConfigureds.get(i).evaluation(arrayListConfusionMatrixs.toArray(new ConfusionMatrix[0]));
//                }
//            }
//
//
//
//
//        }
//
//
//
//
//    }
    private void jButtonTrainPCAActionPerformed() {

        Base b = arrayListBases.get(arrayListBases.size() - 1);
        moduledefault.pca.Pca pca;
        classifierModule.setTextArea(jTextArea1);

        for (int lol = b.getAtributes().length - 1; lol > 0; lol--) {
            pca = new Pca(b);
            jTextArea1.append("==================================\n");
            jTextArea1.append("PCA com " + lol + " Caracteristicas\n");
            long t = System.currentTimeMillis();
            pca.calcula();
            pca.extrair(lol);
            t = System.currentTimeMillis() - t;
            jTextArea1.append(util.Util.getHoraMinSegMiliSeg(t) + "\n");

            long tt = System.currentTimeMillis();
            Base base = arrayListBases.get(arrayListBases.size() - 1);
            double[] evaluationGlobal;
            evaluationGlobal = rodar(base);
            tt= System.currentTimeMillis() -tt;
            System.out.println("PCA\t" + lol + "\t" + evaluationGlobal[0] + "\t" + t+ "\t" + tt);

        }




    }

    private double[] rodar(Base base) {

        BaseClassify[] baseClassifiers = null;
        for (int i = 0; i < arrayListRadioButtonPartionModules.size(); i++) {
            if (arrayListRadioButtonPartionModules.get(i).isSelected()) {
                baseClassifiers = arrayListPartitionModuleConfigureds.get(i).partition(base);
                break;
            }
        }
        ArrayList<ConfusionMatrix> arrayListConfusionMatrixs = new ArrayList<ConfusionMatrix>();

        long tempo = System.currentTimeMillis();

        jTextArea1.append("==================");

        classifierModule.createInstanceClissify(base.getAtributes(), base.getClasses());
        jTextArea1.append(" ==============\n");
        for (BaseClassify baseClassify : baseClassifiers) {


            classifierModule.train(baseClassify.getTrain().getInput(), baseClassify.getTrain().getOutput());
            ConfusionMatrix confusionMatrix = new ConfusionMatrix();
            confusionMatrix.setClasses(base.getClasses());
            for (int i = 0; i < baseClassify.getTest().getInput().length; i++) {
                confusionMatrix.addValue(baseClassify.getTest().getOutput()[i],
                        classifierModule.test(baseClassify.getTest().getInput()[i]));
            }
//                jTextArea1.append("\n============== Matriz de Confusão ==============\n");
//                jTextArea1.append(confusionMatrix.toString() + "\n\n");
            arrayListConfusionMatrixs.add(confusionMatrix);
        }

        tempo = System.currentTimeMillis() - tempo;
        jTextArea1.append(util.Util.getHoraMinSegMiliSeg(tempo) + "\n");

        double[] globalEvaluation = new double[3];
        jTextArea1.append("============== Métricas de Avaliação ==============\n");
        for (int i = 0; i < arrayListCheckBoxEvalutionModules.size(); i++) {
            if (arrayListCheckBoxEvalutionModules.get(i).isSelected()) {
                arrayListEvaluationMetricModuleConfigureds.get(i).setTextArea(jTextArea1);
                arrayListEvaluationMetricModuleConfigureds.get(i).evaluation(arrayListConfusionMatrixs.toArray(new ConfusionMatrix[0]));
                globalEvaluation[i] = arrayListEvaluationMetricModuleConfigureds.get(i).getEvaluationMetricGlobal();
            }
        }

        return globalEvaluation;


    }
}
